﻿using Microsoft.Practices.ObjectBuilder2;

namespace MassPokerTool.Infrastructure.Core.Unity.BuildTrackingExtension
{
    /// <summary>
    /// 
    /// </summary>
    public class BuildTrackingStrategy : BuilderStrategy
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public override void PreBuildUp(IBuilderContext context)
        {
            IBuildTrackingPolicy policy = BuildTracking.GetPolicy(context) ?? BuildTracking.SetPolicy(context);
            policy.BuildKeys.Push(context.BuildKey);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public override void PostBuildUp(IBuilderContext context)
        {
            IBuildTrackingPolicy policy = BuildTracking.GetPolicy(context);
            if (policy != null && policy.BuildKeys.Count > 0)
                policy.BuildKeys.Pop();
        }
    }
}
